<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> 
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>批量下单</title>
<meta http-equiv="expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<link rel="stylesheet" href="../css/admin_style.css" />
<script type="text/javascript" src="../js/core.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<script language="javascript" src="../js/validate.js"></script>
<link rel="stylesheet" href="../css/showloading.css" />
<script type="text/javascript" src="../js/jquery-1.8.2.js"></script>    
<script type="text/javascript" src="../js/jquery.showLoading.min.js"></script>
<script type="text/javascript">
function openNewUrl(id,name,url){
	parent.PW.Dialog({
		'id': id,
		'name': name,
		'url': url
	}).loadIframe(url);
}
</script>
</head>
<body>
<div class="wrap" id="wrap">
<div class="nav3 mb10">
	<ul class="cc">
		<li><a href="${baseIndentType.url2  }">${baseIndentType.name  }</a></li>
		<li><a href="toWeiboAddFor163?base=${baseIndentType.id }">添加单个订单</a></li>
        <li class="current"><a href="toBatchIndentAdd?base=${baseIndentType.id }">批量添加订单</a></li>
        <span class="admin_tips" style="margin-left:10px;line-height:22px;font-weight:bold;">您目前余额：<b style="cursor: pointer; height: 25px; line-height: 25px; font-weight: 700; display: inline-block; color: green;" id="fans_a" onclick="openNewUrl('menu_44','充值消费记录','/agent/accountRecordUI!query.action');return false;" title="查看充值消费记录">${curUser.money }</b></span>  
    </ul>
</div>
<div class="admin_info mb10" style="display: block;">
    <h3 class="h1">提示信息</h3>
    <div class="legend">
    	<li style="font-weight:bold;color:red;">注意：系统按先后顺序添加订单入库，批量提交时请注意余额是否充足。</li>
    		 <li id="pro_li_17" class="selected">
          <b>${baseIndentType.name }</b>：价格优惠后为<font color="red">${price }</font>${baseIndentType.unit }；
           订单数量--最小为<font color="blue">1000/天，不足1000按1000个</font>计费。
       </li>
      <ol>
      </ol>
    </div>
  </div>
<form action="batchIndentAdd?base=${baseIndentType.id }" method="post"  onsubmit="return submitForm(this);">
    <h2 class="h1">${baseIndentType.name }批量详情</h2>
    <div class="admin_table mb10">
      <table width="100%" cellspacing="0" cellpadding="0">
				<tbody>
				<tr class="tr1 vt">
          <td class="td2">
              <textarea name="batchBills" id="batchBills" class="textarea" style="height:200px;float:left;" validate="订单信息||notnull" onblur="formatContent(this);"></textarea>
              <div id="helpinfo" style="float:left;margin-left:12px;height:186px;padding:10px;border:1px dashed #21659A;">
          <b>格式：微博UID+数量，每行一个！</b> <p style="margin-top:10px;">例如：<br>2312312312+1000<br>1234156450+10000<br>1231233132+8000<br>4156465465+6000</p>
              </div></td>
          <td class="td2"><div class="help_a"> </div></td>
        </tr>
      </tbody></table>
    </div>
    <div class="tac mb10">
      <span id="btninfo" style="display:none;font-size:14px;font-weight:bold;color:green;">数据提交时请不刷新 以免重复提交！提交中，请耐心等待结果......</span>
      <span class="btn"><span>
      <button type="submit" id="sbutton">提 交</button>
      </span></span> </div>
  </form>
<div class="c"></div>
<div style="display:none" class="loading-indicator-bars"></div>
</div>
<script type="text/javascript">
String.prototype.myTrim = function()
{
	var lines = new Array();
	lines = this.split(/\s/g);       // 按行分隔处理，否则 /\s/g 可能会匹配到换行符
	var out = "";
	for(var i=0;i<lines.length;i++)
	{
        var line=lines[i];
        if(line && line.length>0){
            out += line + "\n";   // 删除空格
        }
    }
    if(out && out.length>0)
    out=out.substr(0,out.length-1)
    return out;
}
function formatContent(obj){
   obj.value=obj.value.myTrim();
}
function showConfirm(info,href){
 info = info ;//+ "<br>操作理由：<input type='text' id='____operationReason'><br>操作密匙：<input type='text' id='____operationPassword'>";
 showDialog({type:"confirm",message:info,onOk:function(){
   //var ____operationReason=document.getElementById("____operationReason").value;
   //if(!____operationReason || ____operationReason==""){alert("请输入操作理由");return false;}
   location.href=href;
   //openNewUrl('user'+new Date().getTime(),info,href);
   return true;
 }});
}
var operations=document.getElementsByTagName("a");
for(var i=0;i<operations.length;i++){
    var obj=operations[i];
    var confirmDialog=obj.getAttribute("confirm");
    if(!confirmDialog || confirmDialog!="yes")continue;
    obj.attachEvent("onclick",function(e){
        e=window.event||e;
        var el=e.srcElement;
        //test();
        if(el.href.indexOf("javascript:void")==-1)
        el.href="javascript:void(0);showConfirm('"+"确认执行"+el.innerText+"操作？！"+"','"+el.href+"');"
        return false;
    })
}


var user={
	    balance:"${curUser.money }"
	}
	 var product={
	    price:${price},
	    minAmount:${baseIndentType.minAmount},
	    maxAmount:${baseIndentType.maxAmount},
	    unitPrice:${baseIndentType.unit2}
	 };
 function validatePrice()
 {
     var batchBills=document.getElementById("batchBills").value;
     var details=batchBills.split("\n");
     if(details.length==0){
         alert("没有填写任何批量订单信息！");
         return false;
     }
     if(details.length>=30){
         alert("批量订单，一次最多提交30个，目前是"+details.length+"个！");
         return false;
     }
     var feeAll=0;
     for(var i=0;i<details.length;i++){
          var reg=/[A-Za-z0-9]+\+[\d]+/;
         if(!reg.test(details[i])){
             alert("批量订单第【"+(i+1)+"】行："+details[i]+"，UID或订单信息不正确，请去除多余的空行或不符合格式的字符！");
             return false;
         }
         var detail=details[i].split("+");
         var uid=detail[0];
         var amount=Math.abs(parseInt(detail[1]));
         if(amount < product.minAmount)
         {
             amount = product.minAmount;
         }
         else if(billAmount > product.maxAmount)
         {
             amount = product.maxAmount;
         }
         var theFee = Math.round(amount * product.price)/unitPrice;
         feeAll+= theFee;
     }
     if(feeAll>user.balance){
        alert("余额不足，当前批量订单共需："+feeAll+"微币，您目前余额"+user.balance+"微币，请充值后继续！");
        return false;
     }
     return true;
 }


function showConfirm(info,href){
 info = info ;//+ "<br>操作理由：<input type='text' id='____operationReason'><br>操作密匙：<input type='text' id='____operationPassword'>";
 showDialog({type:"confirm",message:info,onOk:function(){
   //var ____operationReason=document.getElementById("____operationReason").value;
   //if(!____operationReason || ____operationReason==""){alert("请输入操作理由");return false;}
   location.href=href;
   //openNewUrl('user'+new Date().getTime(),info,href);
   return true;
 }});
}
var operations=document.getElementsByTagName("a");
for(var i=0;i<operations.length;i++){
    var obj=operations[i];
    var confirm=obj.getAttribute("confirm");
    if(!confirm || confirm!="yes")continue;
    obj.attachEvent("onclick",function(e){
        e=window.event||e;
        var el=e.srcElement;
        //test();
        if(el.href.indexOf("javascript:void")==-1)
        el.href="javascript:void(0);showConfirm('"+"确认执行"+el.innerText+"操作？！"+"','"+el.href+"');"
        return false;
    })
}

var allInputs = document.getElementsByTagName('input');
if(allInputs && allInputs.length>0){
	for(var i=0; i<allInputs.length;i++)
	{
		var ipt = allInputs[i].parentNode;
		if(ipt.tagName=='LI'&& allInputs[i].type=='radio')
		{
			allInputs[i].checked && (ipt.className='current');
			ipt.onclick = function(){radioWithWords(this)};
		}
	}
}
</script>
<script type="text/javascript">
    if (typeof (HTMLElement) != "undefined" && !window.opera) {
    HTMLElement.prototype.__defineGetter__("outerHTML", function () {
        var a = this.attributes, str = "<" + this.tagName, i = 0; for (; i < a.length; i++)
            if (a[i].specified)
                str += " " + a[i].name + '="' + a[i].value + '"';
        if (!this.canHaveChildren)
            return str + " />";
        return str + ">" + this.innerHTML + "</" + this.tagName + ">";
    });
    HTMLElement.prototype.__defineSetter__("outerHTML", function (s) {
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var df = r.createContextualFragment(s);
        this.parentNode.replaceChild(df, this);
        return s;
    });
    HTMLElement.prototype.__defineGetter__("canHaveChildren", function () {
        return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
    });
}
if (typeof (HTMLElement) != "undefined" && !window.opera) {
    HTMLElement.prototype.__defineGetter__("outerHTML", function () {
        var a = this.attributes, str = "<" + this.tagName, i = 0; for (; i < a.length; i++)
            if (a[i].specified)
                str += " " + a[i].name + '="' + a[i].value + '"';
        if (!this.canHaveChildren)
            return str + " />";
        return str + ">" + this.innerHTML + "</" + this.tagName + ">";
    });
    HTMLElement.prototype.__defineSetter__("outerHTML", function (s) {
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var df = r.createContextualFragment(s);
        this.parentNode.replaceChild(df, this);
        return s;
    });
    HTMLElement.prototype.__defineGetter__("canHaveChildren", function () {
        return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
    });
}
</script>
<script type="text/javascript">
    var valueControls={//能直接用 obj.value赋值的控件名及Type
        "input":"text,password,hidden",
        "select":"select-one",
        "textarea":"textarea"
    };
    
    var formData={};
    for(var id in formData){//铺数据
      var obj=document.getElementById(id);
      if(id && obj){//checkBox
        var tagName=obj.tagName.toLowerCase();
        if(obj.type){
          var type=obj.type.toLowerCase();
          if(valueControls[tagName] && valueControls[tagName].indexOf(type)!=-1){
            if(eval("document.getElementById(\""+id+"\")")){
              document.getElementById(id).value=formData[id];
            }
          }else{
             if(type=="radio" || type=="checkbox"){
              initRadioOrCheckBox(id); 
             }
             if(type=="select-multiple"){
              initMultiSelect(id);
             }
          }
        }else{
           obj.innerHTML=formData[id]; 
        }
      }
    }
    function initRadioOrCheckBox(id){
      var servingTimes=document.getElementsByName(id);
      for(var s=0;s<servingTimes.length;s++){
         if(servingTimes[s].type=="checkbox")
           servingTimes[s].checked=false;
      }
      if(formData[id]){
        var servingTimesValue=formData[id].split(",");
        for(var s=0;s<servingTimesValue.length;s++){
         for(var i=0;i<servingTimes.length;i++){
            if(servingTimes[i].value==servingTimesValue[s].trim())
            servingTimes[i].checked=true;
         }
       }
      }else{
       for(var i=0;i<servingTimes.length;i++){
         if(servingTimes[i].type=="checkbox")
           servingTimes[i].checked=true;
       }
      }
   }
   function initMultiSelect(id){
      var selOptions=document.getElementById(id).options;
      for( var i=0;i<selOptions.length;i++){
         selOptions.selected=false;
      }
      if(formData[id]){
        var selOptionsValue=formData[id].split(",");
        for(var s=0;s<selOptionsValue.length;s++){

         for(var i=0;i<selOptions.length;i++){
            if(selOptions[i].value==selOptionsValue[s].trim())
            selOptions[i].selected=true;
         }
       }
      }else{
       for(var i=0;i<selOptions.length;i++){
         selOptions[i].selected=false;
       }
      }
   }
</script>    
<script type="text/javascript">
function getQueryString(form,param) {
        var datastring = '';
        var inputs = form.getElementsByTagName('INPUT');
        for (var i = 0; i < inputs.length; i++) {
            if(inputs[i].name==param)continue;
            
            switch (inputs[i].getAttribute('type')) {
                case 'text':
                    datastring = plamostr(inputs[i], datastring);
                    break;
                case 'hidden':
                    datastring = plamostr(inputs[i], datastring);
                    break;
                case 'checkbox':
                    if (inputs[i].checked) {
                        datastring = plamostr(inputs[i], datastring);
                    }
                    break;
                case 'radio':
                    if (inputs[i].checked) {

                        datastring = plamostr(inputs[i], datastring);
                    }
                    break;
            }
        }
        var textareas = form.getElementsByTagName('TEXTAREA');
        for (var i = 0; i < textareas.length; i++) {
            datastring = plamostr(textareas[i], datastring);
        }
        var selectes = form.getElementsByTagName('SELECT');
        for (var i = 0; i < selectes.length; i++) {
            datastring = plamostr(selectes[i], datastring);
        }
        if(param){
            document.getElementById(param).value=datastring;
        }
        return datastring;
    }
    function plamostr(object, datastring) {
        /**
         *拼装Form数据字符串
         */
        if (datastring.length > 0) {
            datastring += '&' + object.getAttribute('name') + '=' + object.value;
        } else {
            datastring += object.getAttribute('name') + '=' + object.value;
        }
        return datastring;
    }
</script><script type="text/javascript">
    function submitForm(form){
      if(!frmSubmit(form))return false;
      if(!validatePrice())return false;
      document.getElementById("sbutton").disabled=true;
      document.getElementById("sbutton").style.display="none";
      document.getElementById("btninfo").style.display="";
      jQuery('#wrap').showLoading( {
		 'addClass': 'loading-indicator-bars'
	  });
      return true;
    }
</script>
</body></html>


